/**
 * Created By wifi_uncle on 2019/12/30
 */
import API from '../api'
import Utils from '../utils'
import Config from '../config'
import request from '../request'
import axios from 'axios'
export default {
  getRecommendReportList1({ params, _this }) {
    let url = API.DATA_CENTER.GET_RECOMMEND_REPORT_LIST
    let errorMsg = '获取报备推荐列表失败'
    return request.post(url, { params }).then(
      rsp => {
        const data = rsp.body
        if (data && data.result === Config.SUCCESS_CODE) {
          return Promise.resolve(data.resData)
        } else {
          Utils.showFailMsg(errorMsg)
          return Promise.reject(data)
        }
      },
      e => {
        Utils.showFailMsg(errorMsg)
        return Promise.reject(e)
      }
    )
  },

  /**
   * 获取报备推荐列表
   */
  getRecommendReportList({ params, _this }) {
    let url = Utils.getPrefix() + API.DATA_CENTER.GET_RECOMMEND_REPORT_LIST
    let body = {
      params
    }
    let errorMsg = '获取报备推荐列表失败'
    return _this.$http.post(url, body).then(
      rsp => {
        const data = rsp.body
        if (data && data.result === Config.SUCCESS_CODE) {
          return Promise.resolve(data.resData.devPremisesExportPage)
        } else {
          Utils.showFailMsg(errorMsg)
          return Promise.reject(data)
        }
      },
      e => {
        Utils.showFailMsg(errorMsg)
        return Promise.reject(e)
      }
    )
  },
  /**
   * 导出报表数据
   * @param params
   * @param _this
   * @returns {PromiseLike<T> | Promise<T> | * | Promise$1 | PromiseObj}
   */
  exportRecommendReportData({ params, _this }) {
    let url = Utils.getPrefix() + API.DATA_CENTER.EXPORT_RECOMMEND_REPORT_LIST
    let body = {
      params
    }

    return axios({
      method: 'get',
      url: url,
      params: body,
      //   responseType: 'blob',
      headers: {
        userId: sessionStorage.userId || localStorage['1_userId'] || '',
        companyUuid: sessionStorage.companyUuid || ''
      }
    })
      .then(rsp => {
        return rsp
      })
      .catch(err => {
        return err
      })
  },
  /**
   * 查询到访数据报表
   */
  getVisitStateList({ params, _this }) {
    let url = Utils.getPrefix() + API.DATA_CENTER.getVisitStateList
    let body = {
      params
    }
    let errorMsg = '获取到访数据报表失败'
    return _this.$http.post(url, body).then(
      rsp => {
        const data = rsp.body
        if (data && data.result === Config.SUCCESS_CODE) {
          return Promise.resolve(data.resData.getVisitStateList)
        } else {
          Utils.showFailMsg(errorMsg)
          return Promise.reject(data)
        }
      },
      e => {
        Utils.showFailMsg(errorMsg)
        return Promise.reject(e)
      }
    )
  }
}
